<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
    <title>组件</title>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak></div>
    <script src="js/vue.js"></script>
    <script>
        let PublicComp = {
            template: `
            <div>我是公共组件</div>
        `
        };
        //全局组件注册
        Vue.component("PublicComp", PublicComp);
        //首页
        let HomePage = {
            template: `
          <div>
          {{title}}
          <PublicComp></PublicComp>
          </div>
        `,
            data() {
                return {
                    title: "我是首页"
                }
            }
        };
        
        //新闻页面
        let NewsPage = {
            template: `
           <div>
           新闻页面
           <PublicComp></PublicComp>
           </div>
        `
        };

        //入口组件
        let App = {
            template: `
        <div>
            <HomePage></HomePage>
            <NewsPage></NewsPage>
        </div>
      `,
            //局部组件注册方式
            components: {
                HomePage,
                NewsPage
            }
        };
        new Vue({
            el: "#app",
            template: `
                <App></App>
        `,
            components: {
                App
            }
        })
    </script>
</body>

</html>